/* @(#)GSBalanceAuditSelectMonthAction.java   
*
* Project: GS
*
* Modify Information:
* =============================================================================
*   Author       Date       Description
*   ------------ ---------- ---------------------------------------------------
*   Simonyi Peng 2006-4-20    新增
* Copyright Notice:
* =============================================================================
*    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
*        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
*        Haidian District, Beijing ,100081, China All rights reserved.
*
*    This software is the confidential and proprietary information of
*        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
*        You shall not disclose such Confidential Information and shall use it
*        only in accordance with the terms of the license agreement you entered
*        into with HiTRUST.
*
* Warning:
* =============================================================================
* 
*/
package com.hitrust.gs.action;

import java.util.HashMap;
import com.hitrust.gs.bean.GSBalanceParamBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.dao.GSBalanceParamDAO;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.date.DateUtil;

/**
* 
*/
public class GSBalanceAuditSelectMonthAction extends GSBaseAction {

   public String execute(GSBaseForm aForm) throws Exception {
       //取得当前操作员可查询的订货单位和送货地址
       GSOperatorBean tOperBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
       GSOrderDeptInfoProcessor tProc = new GSOrderDeptInfoProcessor();
       HashMap tMap = tProc.getOrderDeptInfoOfBusOper(tOperBean.getGs_oper_org_id());
       aForm.getRequest().setAttribute("orderdept",tMap);
       //取得系统设定的结算日期
       GSBalanceParamDAO tBalParmDAO = new GSBalanceParamDAO();
       GSBalanceParamBean tBean = tBalParmDAO.queryBalanceDate();
       String tCurDay = DateUtil.getCurrentDate("yyyyMMdd");
       if(tBean.getGs_balance_date_type().equals(GSBaseConstants.NATURE_BALANCE_DATE)){
           
           int maxday = DateUtil.getMaxMonthDay(tCurDay);
           tBean.setGs_balance_start_date("1");
           tBean.setGs_balance_end_date(String.valueOf(maxday));
           aForm.getRequest().setAttribute("balancestrdate",DateUtil.formateDateTimeForUser(DateUtil.getSpecDay(1)));
           aForm.getRequest().setAttribute("balanceenddate",DateUtil.formateDateTimeForUser(DateUtil.getSpecDay(maxday)));
       }else{//手动设定参数类型
           int tStrDay = Integer.parseInt(tBean.getGs_balance_start_date());
           int tEndDay = Integer.parseInt(tBean.getGs_balance_end_date());
           int curYear = Integer.parseInt(tCurDay.substring(0,4));
           int curMonth = Integer.parseInt(tCurDay.substring(4,6));
           if(tStrDay > tEndDay || tStrDay == tEndDay){    //开始日期大于等于结束日期
               if(tCurDay.substring(4,6).equals("01")){    //如果当前月份为1月,则开始区间的年为上一年份
                   aForm.getRequest().setAttribute("balancestrdate",DateUtil.getSpecDate(curYear-1,12,tStrDay,"yyyy/MM/dd"));    
                   aForm.getRequest().setAttribute("balanceenddate",DateUtil.getSpecDate(curYear,1,tEndDay,"yyyy/MM/dd"));
               }else {
                   aForm.getRequest().setAttribute("balancestrdate",DateUtil.getSpecDate(curYear,curMonth - 1,tStrDay,"yyyy/MM/dd"));    
                   aForm.getRequest().setAttribute("balanceenddate",DateUtil.getSpecDate(curYear,curMonth,tEndDay,"yyyy/MM/dd"));
               }  
           }else if(tStrDay < tEndDay){        //开始日期小于结束日期
               aForm.getRequest().setAttribute("balancestrdate",DateUtil.getSpecDate(curYear,curMonth,tStrDay,"yyyy/MM/dd"));    
               aForm.getRequest().setAttribute("balanceenddate",DateUtil.getSpecDate(curYear,curMonth,tEndDay,"yyyy/MM/dd"));
           }
       }
       aForm.getRequest().setAttribute("balanceparm",tBean);
       return GSBaseConstants.FORWARD_SUCCESS;
   }

}
